import { defineEmits } from 'vue';

const eventBus = {
  emit: {},
  on: function (event, callback) {
    if (!this.emit[event]) {
      this.emit[event] = [];
    }
    this.emit[event].push(callback);
  },
  off: function (event, callback) {
    if (this.emit[event]) {
      this.emit[event] = this.emit[event].filter(cb => cb !== callback);
    }
  },
  trigger: function (event, data) {
    if (this.emit[event]) {
      this.emit[event].forEach(callback => callback(data));
    }
  }
};

export default eventBus;